﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;
using Helper;
namespace SchoolManagementSystem.Details
{
    public partial class Tracking_Student_Fee_DetailUC : DetailUC
    {
        public Tracking_Student_Fee_DetailUC()
        {
            InitializeComponent();
            this.ObjectName = "Theo dõi";
            this.Code = "Student_Fee_Detail";
            // this.Type = new Student_Fee_Detail();
            this.Type = new Receipt_VoucherFee();

            commandBarUC1.cmdnew.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            date_time.Enabled = false;
        }



        protected override long DetailDisplay()
        {
            Receipt_VoucherFee data = new Receipt_VoucherFee();
            Voucher voucher = new Voucher();
            if (ID > 0)
            {
                data = (Receipt_VoucherFee)RegisterService.RegisterServices.ReceiptVoucherFeeService.GetByID(ID);
                voucher = (Voucher)RegisterService.RegisterServices.VoucherService.GetByID(data.VoucherID);
                // var stid = long.Parse(SearchString.Replace("'", "").Replace("StudentID=", "").Trim());

            }
            else
            {
                date_time.DateTime = DateTime.Now;

            }
            txttimes.Text = data.TimeFee;


            txtno.Text = RegisterService.RegisterServices.ReceiptVoucherFeeService.CalMoneyDebt(data.StudentID, data.TimeFee);
            //lblno.Text = Helper.StringHelper.FormatVND(data.FeeToPayExt);
            txtnote.Text = voucher.Description;
            spinEdit_price.EditValue = data.Money;
            txtreceiptcode.Text = data.ReceiptVoucherCodeExt;
            date_time.DateTime = voucher.CreateDate;

            return ID;
        }

        protected override long Save()
        {

            Receipt_VoucherFee data = new Receipt_VoucherFee();
            if (ID > 0)
            {
                data = (Receipt_VoucherFee)RegisterService.RegisterServices.ReceiptVoucherFeeService.GetByID(ID);
            }

            data.StudentID = long.Parse(SearchString.Replace("'", "").Replace("StudentID=", "").Trim());
            data.TimeFee = txttimes.Text;
            data.Money = int.Parse(spinEdit_price.EditValue.ToString());
            ID = RegisterService.RegisterServices.ReceiptVoucherFeeService.Save(data);

            Voucher voucher = (Voucher)RegisterService.RegisterServices.VoucherService.GetByID(data.VoucherID);

            voucher.Description = txtnote.Text;
            voucher.ModifieDate = DateTime.Now;
            voucher.ModifieBy = ValueDefine.StaffID;
            RegisterService.RegisterServices.VoucherService.Save(voucher, ref ErrorMess);



            return ID;
        }

        public override bool Delete(long SelectedID)
        {
            return RegisterService.RegisterServices.ReceiptVoucherFeeService.Delete(RegisterService.RegisterServices.ReceiptVoucherFeeService.GetByID(SelectedID));

        }

        private void Tracking_Student_Fee_DetailUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(xtraScrollableControl1.Controls);
        }



    }
}
